<?php
//
defined('BY_JYA') or exit('error');
//cfc('core')->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';

if($_RQ['op']=='main'){
	//$post=get_postdata();
	$user=pdo_get('jy_jd_manage',array('uid'=>$_SESSION['uid']));
	if(!$user){
		exi('没有店员权限','','jy_jd/home');
	}
	$params=array('uniacid'=>$_SESSION['uniacid'],'hotelid'=>$user['hotelid']);
	
	$pindex = max(1, intval($post['page']));
	$psize = 15;
	$total='';
	$return['list']=pdo_getslice('jy_jd_order',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	foreach($return['list'] as &$v){
		$v['hotel']=pdo_get('jy_jd_hotel',array('id'=>$v['hotelid']));
		$v['room']=pdo_get('jy_jd_room',array('id'=>$v['roomid']));
		$v['createtime']=date('Y-m-d H:m:s',$v['createtime']);
	}
	exi($return);
}

if($_RQ['op']=='del'){
	if(!$_RQ['id']){
		exi('请先选择订单','error');
	}
	$order=pdo_get('jy_jd_order',array('id'=>$_RQ['id']));
	if($order['status']!=5 && $order['status']!=3){
		exi('只有已完成的订单可以删除','error');
	}
	pdo_delete('jy_jd_order',array('id'=>$_RQ['id']));
	exi('删除成功');
}
if($_RQ['op']=='receive'){
	if(!$_RQ['id']){
		exi('请先选择订单','error');
	}
	$order=pdo_get('jy_jd_order',array('id'=>$_RQ['id']));
	if($order['status']!=0 && $order['status']!=2){
		exi('只有申请取消的订单才能确认取消','error');
	}
		pdo_update('jy_jd_order',array('status'=>3),array('id'=>$_RQ['id']));
		exi('已确认取消');
}
if($_RQ['op']=='in'){
	if(!$_RQ['id']){
		exi('请先选择订单','error');
	}
	$order=pdo_get('jy_jd_order',array('id'=>$_RQ['id']));
	if($order['status']!=0 && $order['ispay']!=1){
		exi('只有已支付未取消订单可以入住','error');
	}
	pdo_update('jy_jd_order',array('status'=>1),array('id'=>$_RQ['id']));
	exi('办理成功');
}
if($_RQ['op']=='done'){
	if(!$_RQ['id']){
		exi('请先选择订单','error');
	}
	$order=pdo_get('jy_jd_order',array('id'=>$_RQ['id']));
	if($order['status']!=1){
		exi('只有已入住订单可以办理退房','error');
	}
	pdo_update('jy_jd_order',array('status'=>5),array('id'=>$_RQ['id']));
	exi('办理成功');
}
?>